export default function useEchartMapOption(mapName) {
  const compId = mapName;
  var center = {
    南京市: [118.767413, 32.041544],
    无锡市: [120.301663, 31.574729],
    徐州市: [117.184811, 34.261792],
    常州市: [119.946973, 31.772752],
    苏州市: [120.619585, 31.299379],
    南通市: [120.864608, 32.016212],
    连云港市: [119.178821, 34.600018],
    淮安市: [119.021265, 33.597506],
    盐城市: [120.139998, 33.377631],
    扬州市: [119.421003, 32.393159],
    镇江市: [119.452753, 32.204402],
    泰州市: [119.915176, 32.484882],
    宿迁市: [118.275162, 33.963008],
  };

  // 定义颜色数组，每个元素对应一个区块的颜色
  var blockColors = [
    "rgba(255,0,0,0.8)",
    "rgba(0,255,0,0.8)",
    "rgba(0,0,255,0.8)",
  ];

  // 定义当前颜色索引
  var currentIndex = 0;

  function getOption(setting) {
    const { zoom, roam } = setting;
    const option = {
      backgroundColor: "rgba(15, 20, 27, 1)",
      tooltip: {
        show: true,
        background: "rgba(0,0,0,.5)",
        textStyle: {
          color: "rgb(0,0,0)",
          fontSize: 12,
          fontFamily: "Courier New",
        },
        formatter: "{a}: {b}",
      },
      geo3D: {
        show: true,
        map: compId,
        viewControl: {
          beta: 0, //x轴旋转
          alpha: 35, //Y轴旋转
          panMouseButton: "right", //平移操作使用的鼠标按键
          rotateMouseButton: "left", //旋转操作使用的鼠标按键
        },
        // 真实感材质相关配置 shading: 'realistic'时有效
        realisticMaterial: {
          detailTexture: "./imgs/detail.webp", // 纹理贴图
          textureTiling: 1, // 纹理平铺，1是拉伸，数字表示纹理平铺次数
          roughness: 1, // 材质粗糙度，0完全光滑，1完全粗糙
          metalness: 0, // 0材质是非金属 ，1金属
          roughnessAdjust: 0,
        },
        light: {
          main: {
            color: "#ffffff",
            intensity: 1,
            // shadow: false,
            shadow: true, // 开启阴影
            shadowQuality: "ultra", // 阴影质量
            // 主光源设置
            //  color: '#ff0000', // 红色光源
            // intensity: 1.2, // 光源强度
          },
          ambient: {
            // 环境光设置
            color: "#000000",
            intensity: 0.1,
          },
        },
        regions: [
          {
            name: "天河区",
            itemStyle: {
              color: "green",
            },
          },
        ],
        itemStyle: {
          color: "#003669",
          borderWidth: 2,
          borderColor: "#fff",
          //  borderColor:'#9ffcff',
          // shadowColor: 'rgba(0,54,255, 1)',
          shadowBlur: 150,
          opcity: 1,
        },
        shading: "realistic",
        label: {
          show: true,
          fontSize: 14,
          color: "#f9fcff",
          fontWeight: 600,
          fontFamily: "Courier New",
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 16,
            color: "#f9fcff",
            fontWeight: 600,
          },
          itemStyle: {
            // color: "#539efe",
            borderWidth: 1,
            borderColor: "#4fdcf7",
          },
        },
        groundPlane: false,
        // 将geo3d放在最底层
        zlevel: -1,
      },
      // geo: {
      //   map: compId,
      //   zoom: 1.1,
      //   zIndex: 99,
      //   show: false,
      // },
      series: [
        {
          tooltip: {
            show: true,
            padding: [6, 10],
            backgroundColor: "rgba(255,255,255,.8)",
            borderColor: "#fff",
            borderRadius: "10px",
            textStyle: {
              align: "left",
              verticalAlign: "middle",
              lineHeight: 26,
              color: "rgba(0,0,0,.7)",
            },
            // data: componentProps.tooltipData
          },
          name: "数据",
          type: "map",
          blendMode: "clear",
          map: compId, // 自定义扩展图表类型
          aspectScale: 1,
          // zoom: 0.6, //缩放
          zoom: -100,
          showLegendSymbol: false,
          label: {
            show: true,
            color: "rgba(255,255,255,1)",
            fontSize: 14,
          },
          data: [
            {
              name: "天河区",
              itemStyle: {
                areaColor: "red",
              },
            },
          ],
          itemStyle: {
            // areaColor: "rgba(14,149,241,1)",
            areaColor: "#003669",
            // borderColor: "rgba(233,233,233,1)",
            borderColor: "rgba(63,218,255,.6)",
            borderWidth: 1,
            shadowColor: "rgba(63, 218, 255,0.6)",
            shadowBlur: 35,
            // shadowColor: "rgba(14,149,241,1)",
            // borderWidth: 1,
            // shadowBlur: 22,
            fontSize: 100,
          },
          emphasis: {
            label: {
              show: true,
              color: "rgba(255,255,255,1)",
              fontSize: 10,
            },
            itemStyle: {
              areaColor: "rgba(255,240,64,.5)",
              borderColor: "rgba(255,255,255,1)",
              borderWidth: 1,
            },
          },
          layoutCenter: ["50%", "50%"],
          layoutSize: "160%",
          markPoint: {
            symbol: "none",
          },
        },
        {
          type: "map3D",
          map: compId,
          // 设置为透明
          itemStyle: {
            color: [1, 1, 1, 0],
          },
          emphasis: {
            itemStyle: {
              color: [1, 1, 1, 0],
            },
          },
          viewControl: {
            beta: 45, //x轴旋转
            alpha: 45, //Y轴旋转
          },
        },
      ],
    };

    return option;
  }
  function updateOption() {}
  // function updateOption({ myChart, option }) {
  //   // // 更新颜色函数
  //   const areaColor = ["天河区", "荔湾区", "黄埔区"];
  //   function updateColors(name) {
  //     option.geo3D.regions = [
  //       {
  //         name,
  //         itemStyle: {
  //           color: "green",
  //         },
  //       },
  //     ];
  //     console.log("option", option);

  //     myChart.setOption(option);
  //     // currentIndex = (currentIndex + 1) % blockColors.length;
  //     // option.series[0].data[0].itemStyle.areaColor = blockColors[currentIndex];
  //   }

  //   // // 每隔一段时间更新一次颜色
  //   let n = 0;
  //   // updateColors(areaColor[n]);
  //   setInterval(() => {
  //     if (n === areaColor.length) {
  //       n = 0;
  //     }
  //     console.log("n", n, areaColor[n])
  //     updateColors(areaColor[n]);
  //     n++;
  //   }, 2000);
  // }

  return {
    getOption,
    // updateOption,
  };
}
